﻿using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using 后整理管理系统.数据分析;
using 纺织贸易管理系统;
using 纺织贸易管理系统.其他窗体;
using 纺织贸易管理系统.设置窗体;

namespace 后整理管理系统.基本资料
{
    public partial class 原料库存 : Form
    {
        public 原料库存()
        {
            InitializeComponent();
            CreateGrid.Create(this.Name, gridView1);
        }

        private void 配置列ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var fm = new 配置列(gridView1) { formname = this.Name, Obj = new RawMaterial() };
            fm.ShowDialog();
        }

        private void 保存样式ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CreateGrid.SaveGridview(this.Name, gridView1);
        }

        private void 导出到EXCELToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ExportFile.导出到文件(gridControl1, "供货商资料");
        }

        private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Query();
        }
        private void Query()
        {
            if (checkBox1.Checked)
            {
                this.gridControl1.DataSource = Connect.GetSugar().Queryable<RawMaterial>().Where(x => x.ProductName.Contains(txtmingcheng.Text) && x.AuxiliaryEncoding.Contains(txtzhujici.Text) && x.CalculateInventory == "是").ToList();
            }
            else
            {
                this.gridControl1.DataSource = Connect.GetSugar().Queryable<RawMaterial>().Where(x => x.ProductName.Contains(txtmingcheng.Text) && x.AuxiliaryEncoding.Contains(txtzhujici.Text) && x.CalculateInventory == "是"&&x.InventoryQuantity!=0).ToList();
            }
        }

        private void 原料库存_Load(object sender, EventArgs e)
        {
            Query();
        }

        private void 查看明细ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var raw=gridView1.GetRow(gridView1.FocusedRowHandle) as RawMaterial;
            if (raw != null) { 
                var fm=new 原料进出明细() { Raw=raw }.ShowDialog();
            }
        }
    }
}
